using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using CommandBuilder;
using Android.Hardware;
using System.Collections.Generic;
using Common;

namespace AndroidLinkClient
{
	/// <summary>
	/// Keyboard.
	/// </summary>
	[Activity (Label = "Keyboard")]			
	public class Keyboard : Activity
	{
		Command keyCommand = new Command();

		/// <summary>
		/// Raises the create event.
		/// </summary>
		/// <param name='bundle'>
		/// Bundle.
		/// </param>
		protected override void OnCreate(Bundle bundle)
		{
				base.OnCreate(bundle);
				
				// Set our view from the "main" layout resource
				SetContentView(Resource.Layout.Keyboard);

				#region F
				Button F1 = FindViewById<Button>(Resource.Id.F1);
				Button F2 = FindViewById<Button>(Resource.Id.F2);
				Button F3 = FindViewById<Button>(Resource.Id.F3);
				Button F4 = FindViewById<Button>(Resource.Id.F4);
				Button F5 = FindViewById<Button>(Resource.Id.F5);
				Button F6 = FindViewById<Button>(Resource.Id.F6);
				Button F7 = FindViewById<Button>(Resource.Id.F7);
				Button F8 = FindViewById<Button>(Resource.Id.F8);
				Button F9 = FindViewById<Button>(Resource.Id.F9);
				Button F10 = FindViewById<Button>(Resource.Id.F10);
				
				F1.Click += delegate
				{
					Send(F1.Text);
				};
				F2.Click += delegate
				{
					Send(F2.Text);
				};
				F3.Click += delegate
				{
					Send(F3.Text);
				};
				F4.Click += delegate
				{
					Send(F4.Text);
				};
				F5.Click += delegate
				{
					Send(F5.Text);
				};
				F6.Click += delegate
				{
					Send(F6.Text);
				};
				F7.Click += delegate
				{
					Send(F7.Text);
				};
				F8.Click += delegate
				{
					Send(F8.Text);
				};
				F9.Click += delegate
				{
					Send(F9.Text);
				};
				F10.Click += delegate
				{
					Send(F10.Text);
				};
#endregion
				
				#region N
				Button N1 = FindViewById<Button>(Resource.Id.N1);
				Button N2 = FindViewById<Button>(Resource.Id.N2);
				Button N3 = FindViewById<Button>(Resource.Id.N3);
				Button N4 = FindViewById<Button>(Resource.Id.N4);
				Button N5 = FindViewById<Button>(Resource.Id.N5);
				Button N6 = FindViewById<Button>(Resource.Id.N6);
				Button N7 = FindViewById<Button>(Resource.Id.N7);
				Button N8 = FindViewById<Button>(Resource.Id.N8);
				Button N9 = FindViewById<Button>(Resource.Id.N9);
				Button N0 = FindViewById<Button>(Resource.Id.N0);
				N1.Click += delegate
				{
					Send(N1.Text);
				};
				N2.Click += delegate
				{
					Send(N2.Text);
				};
				N3.Click += delegate
				{
					Send(N3.Text);
				};
				N4.Click += delegate
				{
					Send(N4.Text);
				};
				N5.Click += delegate
				{
					Send(N5.Text);
				};
				N6.Click += delegate
				{
					Send(N6.Text);
				};
				N7.Click += delegate
				{
					Send(N7.Text);
				};
				N8.Click += delegate
				{
					Send(N8.Text);
				};
				N9.Click += delegate
				{
					Send(N9.Text);
				};
				N0.Click += delegate
				{
					Send(N0.Text);
				};
#endregion
				
				#region q
				Button Q = FindViewById<Button>(Resource.Id.Q);
				Button W = FindViewById<Button>(Resource.Id.W);
				Button E = FindViewById<Button>(Resource.Id.E);
				Button R = FindViewById<Button>(Resource.Id.R);
				Button T = FindViewById<Button>(Resource.Id.T);
				Button Y = FindViewById<Button>(Resource.Id.Y);
				Button U = FindViewById<Button>(Resource.Id.U);
				Button I = FindViewById<Button>(Resource.Id.I);
				Button O = FindViewById<Button>(Resource.Id.O);
				Button P = FindViewById<Button>(Resource.Id.P);
				Q.Click += delegate
				{
					Send(Q.Text);
				};
				W.Click += delegate
				{
					Send(W.Text);
				};
				E.Click += delegate
				{
					Send(E.Text);
				};
				R.Click += delegate
				{
					Send(R.Text);
				};
				T.Click += delegate
				{
					Send(T.Text);
				};
				Y.Click += delegate
				{
					Send(Y.Text);
				};
				U.Click += delegate
				{
					Send(U.Text);
				};
				I.Click += delegate
				{
					Send(I.Text);
				};
				O.Click += delegate
				{
					Send(O.Text);
				};
				P.Click += delegate
				{
					Send(P.Text);
				};
#endregion
				
				#region A
				Button A = FindViewById<Button>(Resource.Id.A);
				Button S = FindViewById<Button>(Resource.Id.S);
				Button D = FindViewById<Button>(Resource.Id.D);
				Button F = FindViewById<Button>(Resource.Id.F);
				Button G = FindViewById<Button>(Resource.Id.G);
				Button H = FindViewById<Button>(Resource.Id.H);
				Button J = FindViewById<Button>(Resource.Id.J);
				Button K = FindViewById<Button>(Resource.Id.K);
				Button L = FindViewById<Button>(Resource.Id.L);
				Button ENTER = FindViewById<Button>(Resource.Id.ENTER);
				A.Click += delegate
				{
					Send(A.Text);
				};
				S.Click += delegate
				{
					Send(S.Text);
				};
				D.Click += delegate
				{
					Send(D.Text);
				};
				F.Click += delegate
				{
					Send(F.Text);
				};
				G.Click += delegate
				{
					Send(G.Text);
				};
				H.Click += delegate
				{
					Send(H.Text);
				};
				J.Click += delegate
				{
					Send(J.Text);
				};
				K.Click += delegate
				{
					Send(K.Text);
				};
				L.Click += delegate
				{
					Send(L.Text);
				};
				ENTER.Click += delegate
				{
					Send(ENTER.Text);
				};
#endregion
				
				#region Z
				Button Z = FindViewById<Button>(Resource.Id.Z);
				Button X = FindViewById<Button>(Resource.Id.X);
				Button C = FindViewById<Button>(Resource.Id.C);
				Button V = FindViewById<Button>(Resource.Id.V);
				Button B = FindViewById<Button>(Resource.Id.B);
				Button N = FindViewById<Button>(Resource.Id.N);
				Button M = FindViewById<Button>(Resource.Id.M);
				Button SHIFT = FindViewById<Button>(Resource.Id.SHIFT);
				Button BACK = FindViewById<Button>(Resource.Id.BACK);
				Z.Click += delegate
				{
					Send(Z.Text);
				};
				X.Click += delegate
				{
					Send(X.Text);
				};
				C.Click += delegate
				{
					Send(C.Text);
				};
				V.Click += delegate
				{
					Send(V.Text);
				};
				B.Click += delegate
				{
					Send(B.Text);
				};
				N.Click += delegate
				{
					Send(N.Text);
				};
				M.Click += delegate
				{
					Send(M.Text);
				};
				SHIFT.Click += delegate
				{
					Send(SHIFT.Text);
				};
				BACK.Click += delegate
				{
					Send(BACK.Text);
				};
#endregion
				
				#region CTRL
			Button CTRL = FindViewById<Button>(Resource.Id.CTRL);
			Button ALT = FindViewById<Button>(Resource.Id.ALT);
			Button SPACE = FindViewById<Button>(Resource.Id.SPACE);
			Button TAB = FindViewById<Button>(Resource.Id.TAB);
			Button CAPLOCK = FindViewById<Button>(Resource.Id.CAP);
			Button ESC = FindViewById<Button>(Resource.Id.ESC);
			CTRL.Click += delegate
			{
				Send(CTRL.Text);
			};
			ALT.Click += delegate
			{
				Send(ALT.Text);
			};
			SPACE.Click += delegate
			{
				Send(SPACE.Text);
			};
			TAB.Click += delegate
			{
				Send(TAB.Text);
			};
			CAPLOCK.Click += delegate
			{
				Send(CAPLOCK.Text);
			};
			ESC.Click += delegate
			{
				Send(ESC.Text);
			};
#endregion
		}

		/// <summary>
		/// Send the specified text.
		/// </summary>
		/// <param name='text'>
		/// Text.
		/// </param>
		void Send (string text)
		{
            keyCommand.Commands.Clear();
			keyCommand.Type = "keyboardd";
			keyCommand.Operation = "click";
			keyCommand.Commands.Add(new CommandItem(){Name = "key",Value = text});
			Work._default.Send(Creator.CreateXml(keyCommand));
		}
	}
}